package com.business.action.oa;

import javax.servlet.http.HttpServletRequest;

import com.business.bean.oa.CalendarSortBean;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import net.sf.rose.jdbc.DBUtils;
import net.sf.rose.jdbc.PageBean;
import net.sf.rose.jdbc.dao.BeanDAO;
import net.sf.rose.jdbc.query.BeanSQL;
import net.sf.rose.jdbc.service.Service;

/**
 * 日历排班分类管理
 * 
 * @author fengjian
 */
@Controller
@RequestMapping("/oa/calendar/sort")
public class CalendarSortAction {

	/**
	 * 获取某个部门下一整年的日历，如果没有就创建它
	 */
	@ResponseBody
	@RequestMapping("/list.do")
	public PageBean list(HttpServletRequest request, Service service, String year, String departID) {
		PageBean page = new PageBean();
		BeanDAO dao = new BeanDAO(service);
		BeanSQL query = dao.getQuerySQL();
		query.setEntityClass(CalendarSortBean.class);
		query.createSql();
		page.setData(dao.list());
		return page;
	}

	/**
	 * 设置上下班时间
	 */
	@ResponseBody
	@RequestMapping("/save.do")
	public PageBean save(Service service, CalendarSortBean bean) {
		PageBean res = new PageBean();
		BeanDAO dao = new BeanDAO(service);
		BeanSQL query = dao.getQuerySQL();
		query.setEntityClass(CalendarSortBean.class);
		query.createSaveSql(bean);
		if (dao.update() > 0) {
			res.setMessage("保存信息成功！");
		} else {
			res.setSuccess(false);
			res.setMessage("保存信息失败！");
		}
		return res;
	}

	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete.do")
	public PageBean delete(HttpServletRequest request, Service service, String sortID) {
		return DBUtils.delete(service, CalendarSortBean.class, sortID);
	}
}
